<template>
	<view class="all-main">
		<u-loading-page :loading="loadding" loading-mode="semicircle" loading-text="欢迎进入风动社区"></u-loading-page>
		<view v-if="!loadding" class="main">
			<view class="tops">
				<view class="account">
					<view class="img">
						<u--image :src="avatar" width="50" height="50" shape="circle"></u--image>
					</view>
					<view class="name">
						{{customerinfo.nickname}}
					</view>
				</view>
				<view class="account-count">
					<view class="items">
						<view class="title" @click="details(1)">
							{{total.paramA.title}}
						</view>
						<view class="nums" @click="details(1)">
							{{total.paramA.total}}
						</view>
					</view>
					<view class="items">
						<view class="title" @click="details(2)">
							{{total.paramB.title}}
						</view>
						<view class="nums" @click="details(2)">
							{{total.paramB.total}}
						</view>
					</view>
				</view>
			</view>
			<view class="functions">
				<view v-for="(item, index) in menu" :key="index" class="items" @click="pathTo(item.path)">
					<image class="img" :src="item.imgUrl" mode="aspectFit"></image>
					<text>{{item.name}}</text>
				</view>
			</view>
		</view>
		<u-tabbar :value="value2" :placeholder="false" @change="changeMenu" :fixed="true" :safeAreaInsetBottom="true">
			<u-tabbar-item text="首页" icon="bag"></u-tabbar-item>
			<u-tabbar-item text="我的" icon="order"></u-tabbar-item>
		</u-tabbar>
	</view>
</template>

<script>
	var util = require('@/util/request5.js');
	export default {
		data() {
			return {
				loadding: true,
				customerinfo: {},
				avatar: '/static/default.jpg',
				total: {
					paramA: {
						title: '申领数量',
						total: 0
					},
					paramB: {
						title: '反馈数量',
						total: 0
					}
				},
				menu: [],
				openid: '',
				value2: 0,
				
			}
		},
		onLoad(e) {
			this.customerinfo = uni.getStorageSync('customerinfo');
			if(this.customerinfo.avatar != '') {
				this.avatar = this.customerinfo.avatar
			}
			this.getData()
			this.getIndexData()
		},
		onShow() {
			this.getIndexData()
		},
		onBackPress(options) {
			var ua = window.navigator.userAgent.toLowerCase();
			if (ua.match(/MicroMessenger/i) == 'micromessenger') {
			    WeixinJSBridge.call('closeWindow');
			} else {
			    window.close();
			}
			return true
		},
		methods: {
			// 底部链接
			changeMenu(index) {
				uni.navigateTo({
					url: '/pages/public/mine?type=1'
				})
			},
			// 首页统计
			async getIndexData() {
				const {
					data: res
				} = await this.$myHttp5({
					url: 'v1/indexCount',
					header: {
						'token': this.customerinfo.token
					}
				});
				if (res.code == 1) {
					this.total = res.data
				}
			},
			// 获取栏目数据
			async getData() {
				const {
					data: res
				} = await this.$myHttp5({
					url: 'Menu/lists',
					data: {
						type: 1
					},
					header: {
						'token': this.customerinfo.token
					}
				});
				this.loadding = false
				if (res.code == 1) {
					res.data.map(item => {
						item.imgUrl = util.API_URL + item.imgUrl
					})
					this.menu = res.data
				}
			},
			// 跳转
			pathTo(path) {
				uni.navigateTo({
					url: path
				})
			},
			// 首页统计跳转
			details(type) {
				if (type == 1) {
					uni.navigateTo({
						url: '/pages/customer/apply/index'
					})
				} else {
					if (this.customerinfo.is_typs == 5) {
						uni.navigateTo({
							url: '/pages/customer/feedback/index'
						})
					} else {
						uni.navigateTo({
							url: '/pages/customer/terminalOrder/index'
						})
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f3f4f6;
	}

	.all-main {
		.main {
			.tops {
				background: url('/static/mine_bg.png') no-repeat center;
				background-size: 100% 100%;
				height: 400rpx;
				position: relative;

				.account {
					text-align: center;
					color: #ffffff;
					padding: 60rpx 0;
					font-size: 50rpx;
					font-weight: bold;
					
					.img {
						display: flex;
						justify-content: center;
						text-align: center;
					}

					.name {
						font-size: 32rpx;
						padding-bottom: 10rpx;
						padding-top: 16rpx;
					}
				}

				.account-count {
					display: flex;
					justify-content: space-between;

					.items {
						width: 50%;
						text-align: center;
						color: #ffffff;

						.title {
							color: #f3f4f6;
							padding-bottom: 10rpx;
							font-size: 26rpx;
							font-weight: bold;
						}

						.nums {
							font-weight: bold;
						}
					}
				}
			}

			.msgs {
				background-color: #ffffff;
				padding: 30rpx;
				display: flex;
				justify-content: space-between;
			}

			.functions {
				margin-top: 30rpx;
				background-color: #ffffff;
				padding: 30rpx;
				display: flex;
				flex-wrap: wrap;

				.items {
					display: flex;
					flex-direction: column;
					align-items: center;
					min-width: 25%;
					margin-bottom: 20rpx;

					.img {
						width: 80rpx;
						height: 80rpx;
						padding: 20rpx;
					}
				}
			}
		}
	}
</style>